
#ifndef MPI_ISP_H
#define MPI_ISP_H

#ifdef  __cplusplus
extern "C"
{
#endif


#define HIST_BIN_NUM    					64
#define NUM_CHROMA_GAIN_CURVE           	(128)
#define RGB_TO_YUV_MATRIX_SIZE          	(9)
#define	MCTF_CFG_SIZE						(528)
#define	RGB_AAA_DATA_BLOCK				(2048)
#define	CFA_AAA_DATA_BLOCK				(12416)
#define	RGB_AAA_DATA_BLOCK_SIZE			(RGB_AAA_DATA_BLOCK*(4))
#define	CFA_AAA_DATA_BLOCK_SIZE			(CFA_AAA_DATA_BLOCK*(4))
#define	MAX_TILES_H						(33)
#define	MAX_TILES_V						(33)
#define	MAX_VIGNETTE_NUM					(MAX_TILES_H * MAX_TILES_V * (2))
#define	NUM_OUT_LOOKUP						(256)
#define	NUM_IN_LOOKUP						(576)
#define	NUM_MATRIX							(4096)
#define	K0123_ARRAY_SIZE					(24)
#define	DYN_BPC_THD_TABLE_SIZE			((3)*(128)*(2))




struct isp_statistics
{
	u8      *rgb_data_valid;
	u8      *cfa_data_valid;
	u8      *hist_data_valid;
	void    *rgb_statis;
	void    *cfa_statis;
	void    *hist_statis;
};


typedef struct aaa_tile_info_s
{
	u16 awb_tile_col_start;
	u16 awb_tile_row_start;
	u16 awb_tile_width;
	u16 awb_tile_height;
	u16 awb_tile_active_width;
	u16 awb_tile_active_height;
	u16 awb_rgb_shift;
	u16 awb_y_shift;
	u16 awb_min_max_shift;
	u16 ae_tile_col_start;
	u16 ae_tile_row_start;
	u16 ae_tile_width;
	u16 ae_tile_height;
	u16 ae_y_shift;
	u16 ae_linear_y_shift;
	u16 af_tile_col_start;
	u16 af_tile_row_start;
	u16 af_tile_width;
	u16 af_tile_height;
	u16 af_tile_active_width;
	u16 af_tile_active_height;
	u16 af_y_shift;
	u16 af_cfa_y_shift;
	u8  awb_tile_num_col;
	u8  awb_tile_num_row;
	u8  ae_tile_num_col;
	u8  ae_tile_num_row;
	u8  af_tile_num_col;
	u8  af_tile_num_row;
	u8  total_slices_x;
	u8  total_slices_y;
	u8  slice_index_x;
	u8  slice_index_y;
	u16 slice_width;
	u16 slice_height;
	u16 slice_start_x;
	u16 slice_start_y;

	u16 reserved[32];
} aaa_tile_info_t;

typedef struct cfa_awb_stat_s
{
	u16 sum_r;
	u16 sum_g;
	u16 sum_b;
	u16 count_min;
	u16 count_max;
} cfa_awb_stat_t;

typedef struct cfa_ae_stat_s
{
	u16 lin_y;
	u16 count_min;
	u16 count_max;
} cfa_ae_stat_t;


typedef struct cfa_af_stat_s
{
	u16 sum_fy;
	u16 sum_fv1;
	u16 sum_fv2;
} cfa_af_stat_t;

typedef struct cfa_histogram_stat_s
{
	u32 his_bin_r[HIST_BIN_NUM];
	u32 his_bin_g[HIST_BIN_NUM];
	u32 his_bin_b[HIST_BIN_NUM];
	u32 his_bin_y[HIST_BIN_NUM];
} cfa_histogram_stat_t;

typedef struct cfa_aaa_stat_s
{
	aaa_tile_info_t         tile_info;
	cfa_awb_stat_t          awb_stat[1024];
	cfa_ae_stat_t           ae_stat[96];
	cfa_af_stat_t           af_stat[40];
	cfa_histogram_stat_t    histogram_stat;
	u8                      reserved[208];
} cfa_aaa_stat_t;


typedef struct rgb_histogram_stat_s
{
	u32 his_bin_y[HIST_BIN_NUM];
	u32 his_bin_r[HIST_BIN_NUM];
	u32 his_bin_g[HIST_BIN_NUM];
	u32 his_bin_b[HIST_BIN_NUM];
} rgb_histogram_stat_t;


typedef struct rgb_aaa_stat_s
{
	aaa_tile_info_t         tile_info;
	cfa_af_stat_t           af_stat[40];
	u16                     ae_sum_y[96];
	rgb_histogram_stat_t    histogram_stat;
	u8                      reserved[464];
} rgb_aaa_stat_t;




typedef struct sgks_aaa_statistics_config
{
	u8  enable;
	u8  auto_shift;
	u16 awb_tile_num_col;
	u16 awb_tile_num_row;
	u16 awb_tile_col_start;
	u16 awb_tile_row_start;
	u16 awb_tile_width;
	u16 awb_tile_height;
	u16 awb_tile_active_width;
	u16 awb_tile_active_height;
	u16 awb_pix_min_value;
	u16 awb_pix_max_value;
	u16 ae_tile_num_col;
	u16 ae_tile_num_row;
	u16 ae_tile_col_start;
	u16 ae_tile_row_start;
	u16 ae_tile_width;
	u16 ae_tile_height;
	u16 af_tile_num_col;
	u16 af_tile_num_row;
	u16 af_tile_col_start;
	u16 af_tile_row_start;
	u16 af_tile_width;
	u16 af_tile_height;
	u16 af_tile_active_width;
	u16 af_tile_active_height;
	u16 ae_pix_min_value;
	u16 ae_pix_max_value;
} SGKS_AAA_STATISTICS_CONFIG_S;




struct aaa_statistics_ex
{
	u8 af_horizontal_filter1_mode;
	u8 af_horizontal_filter1_stage1_enb;
	u8 af_horizontal_filter1_stage2_enb;
	u8 af_horizontal_filter1_stage3_enb;
	s16 af_horizontal_filter1_gain[7];
	u16 af_horizontal_filter1_shift[4];
	u16 af_horizontal_filter1_bias_off;
	u16 af_horizontal_filter1_thresh;
	u16 af_vertical_filter1_thresh;
	u16 af_tile_fv1_horizontal_shift;
	u16 af_tile_fv1_vertical_shift;
	u16 af_tile_fv1_horizontal_weight;
	u16 af_tile_fv1_vertical_weight;

	u8 af_horizontal_filter2_mode;
	u8 af_horizontal_filter2_stage1_enb;
	u8 af_horizontal_filter2_stage2_enb;
	u8 af_horizontal_filter2_stage3_enb;
	s16 af_horizontal_filter2_gain[7];
	u16 af_horizontal_filter2_shift[4];
	u16 af_horizontal_filter2_bias_off;
	u16 af_horizontal_filter2_thresh;
	u16 af_vertical_filter2_thresh;
	u16 af_tile_fv2_horizontal_shift;
	u16 af_tile_fv2_vertical_shift;
	u16 af_tile_fv2_horizontal_weight;
	u16 af_tile_fv2_vertical_weight;
};


struct black_level_global_offset
{
	s32 global_offset_ee;
	s32 global_offset_eo;
	s32 global_offset_oe;
	s32 global_offset_oo;
	u16 black_level_offset_red;
	u16 black_level_offset_green;
	u16 black_level_offset_blue;
};

struct bad_pixel_correct_info
{
	u32 dynamic_bad_pixel_enable;
	u32 correction_mode;
	u32 hot_pixel_addr;
	u32 dark_pixel_addr;
	u16 shift0_4;
	u16 shift5;
};


struct cfa_leakage_filter_info
{
	u32 enable;
	s8  alpha_rr;
	s8  alpha_rb;
	s8  alpha_br;
	s8  alpha_bb;
	u16 saturation_level;
	u16 threshold;
	u8  shift;
};


typedef struct cfa_noise_filter_info_s
{
	u32 enable;
	u32 iso_center_weight_red;
	u32 iso_center_weight_green;
	u32 iso_center_weight_blue;
	u32 iso_thresh_k0_red;            /* 13:0 */
	u32 iso_thresh_k0_green;        /* 13:0 */
	u32 iso_thresh_k0_blue;            /* 13:0 */
	u32 iso_thresh_k0_close;        /* 13:0 */
	u32 iso_thresh_k1_red;            /* 5:0 */
	u32 iso_thresh_k1_green;        /* 5:0 */
	u32 iso_thresh_k1_blue;            /* 5:0 */
	u32 direct_center_weight_red;
	u32 direct_center_weight_green;
	u32 direct_center_weight_blue;
	u32 direct_thresh_k0_red;
	u32 direct_thresh_k0_green;
	u32 direct_thresh_k0_blue;
	u32 direct_thresh_k1_red;
	u32 direct_thresh_k1_green;
	u32 direct_thresh_k1_blue;
	u32 direct_grad_thresh;
} cfa_noise_filter_info_t;


struct vignette_compensation_info
{
	u8  enable;
	u8  gain_shift;
	u16 group_index;
	u32 vignette_red_gain_ptr;
	u32 vignette_green_even_gain_ptr;
	u32 vignette_green_odd_gain_ptr;
	u32 vignette_blue_gain_ptr;
};

#define NUM_EXPOSURE_CURVE		256
struct local_exposure_info
{
	u16	enable;
	u16	group_index;
	u32	radius;					/* 0-7 */
	u8	luma_weight_red;			/* 4:0 */
	u8	luma_weight_green;			/* 4:0 */
	u8	luma_weight_blue;			/* 4:0 */
	u8	luma_weight_sum_shift;			/* 4:0 */
	u16	gain_curve_table[NUM_EXPOSURE_CURVE];	/* 11:0 */
	u16	black_level_offset_red;
	u16	black_level_offset_green;
	u16	black_level_offset_blue;
	u16	luma_offset;
	u16	global_offset;
};


struct color_correction_info
{
	u8  enable;
	u8  no_interpolation;
	u8  yuv422_foramt;
	u8  uv_center;
	u32 multi_red;              /* 16:0 */
	u32 multi_green;            /* 16:0 */
	u32 multi_blue;             /* 16:0 */
	u32 *in_lut_addr;           /* r[2k] 11:0, r[2k+1] 23:12 */
	u32 *matrix_addr;           /* r[k] 9:0, g[k] 19:10, b[k] 29:20 */
	u32 output_lookup_bypass;
	u32 *out_lut_addr;          /* r[k] 9:0, g[k] 19:10 b[k] 29:20 */
	u32 group_index;
};



struct rgb_to_yuv_info
{
	s16 matrix_values[RGB_TO_YUV_MATRIX_SIZE];
	s16 y_offset;
	s16 u_offset;
	s16 v_offset;
	u32 group_index;
};

struct chroma_scale_info
{
	u32 enable;
	u32 make_legal;
	s16 u_weight_0;
	s16 u_weight_1;
	s16 u_weight_2;
	s16 v_weight_0;
	s16 v_weight_1;
	s16 v_weight_2;
	u32 gain_curver_addr;     //gain_curver_addr
	u32 group_index;
	u16 gain_curve[NUM_CHROMA_GAIN_CURVE];    /* 11:0 */
};

struct chroma_median_filter
{
	u32	enable;
	u32	group_index;
	u32	k0123_table_addr;
	u16	u_sat_t0;
	u16	u_sat_t1;
	u16	v_sat_t0;
	u16	v_sat_t1;
	u16	u_act_t0;
	u16	u_act_t1;
	u16	v_act_t0;
	u16	v_act_t1;
};


#define NUM_ALPHA_TABLE	512
struct luma_sharpening_info
{
	u32	enable;
	u32	grad_thresh_0;
	u32	grad_thresh_1;
	u32	smooth_shift;
	u32	edge_shift;
	u32	edge_thresh;
	u32	alpha_table_addr; 		// alpha_table_addr
	u32	group_index;
	u32	unsharp_mask[6];	// a6
	u8	clip_low;		 
	u8	clip_high;
	u8	max_change_down;
	u8	max_change_up;
	u8	alpha_table[NUM_ALPHA_TABLE];
};

struct luma_sharp_fir_info
{
	u8	enable_fir1;
	u8	enable_fir2;
	u16	enable_fir2_bypass_alpha;
	u32	fir0_clip_low;
	u32	fir0_clip_high;
	s32	fir1_clip_low;
	s32	fir1_clip_high;
	s32	fir2_clip_low;
	s32	fir2_clip_high;
	u32	coeff_fir0_addr;
	u32	coeff_fir1_addr;
	u32	coeff_fir2_addr;
	u32	coring_table_addr;
	u32	group_index;
};

struct luma_sharp_edge_info
{
	u32	group_index;
	u16	edge_thresh;
	u8	edge_thresh_multi;
	u8 	wide_weight;
	u8	narrow_weight;
};

struct luma_sharp_blend_info
{
	u32	group_index;
	u16	enable;
	u8	edge_thresh_multi;
	u8	iso_thresh_multi;
	u16	edge_thresh0;
	u16	edge_thresh1;
	u16	dir_thresh0;
	u16	dir_thresh1;
	u16	iso_thresh0;
	u16	iso_thresh1;
};

struct luma_sharp_level_info
{
	u32	group_index;
	u32	select;
	u8	low;
	u8	low_0;
	u8	low_delta;
	u8	low_val;
	u8	high;
	u8	high_0;
	u8	high_delta;
	u8	high_val;
	u8	base_val;
	u8	area;
	u16	lvl_ctrl_clip_low;
	u16	lvl_ctrl_clip_low2;
	u16	lvl_ctrl_clip_high;
	u16	lvl_ctrl_clip_high2;
};


struct luma_sharp_misc_info
{
	u32	group_index;
	u8	coring_control;
	u8	add_in_low_pass;
	u8	second_input_enable;
	u8	second_input_signed;
	u8	second_input_shift;
	u8	output_signed;
	u8	output_shift;
	u8	abs;
	u8	yuv;
};

struct mctf_gmv_info
{
	u32	enable_external_gmv;
	u32	external_gmv;
};

struct mctf_mv_stab_info
{
	u8	noise_filter_strength;
	u8	image_stabilize_strength;
	u8	still_noise_filter_strength;
	u8	reserved;
	u32	mctf_cfg_dram_addr;
};

struct rgb_gain_info
{
	u32 r_gain;
	u32 g_even_gain;
	u32 g_odd_gain;
	u32 b_gain;
	u32 group_index;
};

struct anti_aliasing_info
{
	u32 enable;
	u32 threshold;
	u32 shift;
};



struct digital_gain_level
{
	u32 level_red;
	u32 level_green_even;
	u32 level_green_odd;
	u32 level_blue;
	u32 group_index;
};

typedef struct zoom_factor_info_s
{
	u32 zoom_x;
	u32 zoom_y;
	u32 x_center_offset;
	u32 y_center_offset;
} zoom_factor_info_t;


struct demoasic_filter_info
{
	u16 enable;
	u16 group_index;
	u32 grad_clip_thresh;			/* 11:0 */
	u32 grad_noise_thresh;			/* 11:0 */
	u32 act_thresh;        
	u32 act_diff_thresh;  //
};


struct sensor_info
{
	u8 sensor_id;
	u8 field_format;          /**< Field */
	u8 sensor_resolution;     /**< Number of bits for data representation */
	u8 sensor_pattern;        /**< Bayer patterns RG, BG, GR, GB */
	u8 first_line_field_0;
	u8 first_line_field_1;
	u8 first_line_field_2;
	u8 first_line_field_3;
	u8 first_line_field_4;
	u8 first_line_field_5;
	u8 first_line_field_6;
	u8 first_line_field_7;
	u32 sensor_readout_mode;
};

struct fixed_pattern_correct
{
	u32 fpn_pixel_mode;
	u32 row_gain_enable;
	u32 column_gain_enable;
	u32 num_of_rows;
	u16 num_of_cols;
	u16 fpn_pitch;
	u32 fpn_pixels_addr;
	u32 fpn_pixels_buf_size;
	u32 intercept_shift;
	u32 intercepts_and_slopes_addr;
	u32 row_gain_addr;
	u32 column_gain_addr;
};


typedef enum
{
    SGKS_FALSE = 0,  /*!< Logical false. */
    SGKS_TRUE  = 1   /*!< Logical true. */
} SGKS_BOOL;

typedef struct
{

    u32 ispModuleIndex;
    SGKS_BOOL bEnhance3D;
} SGKS_ISP_OpenParamsT;

typedef enum {
    GADI_ISP_WB_TYPE_AUTO,
    GADI_ISP_WB_TYPE_MANUAL,
} SGKS_ISP_WbTypeEnumT;


signed int sgks_image_init(void);
signed int sgks_image_exit(void);
void* sgks_image_open(SGKS_ISP_OpenParamsT *openParamPtr, signed int *errorCodePtr);
signed int sgks_image_close(void* ispHandle);
signed int sgks_image_load_param(void* ispHandle, const char *paramFile);
signed int  sgks_image_isp_start(void* ispHandle);
signed int  sgks_image_isp_stop(void* ispHandle);
int sgks_mpi_isp_cmd(u32 cmd, u8 *arg);
int sgks_mpi_isp_SetMpiToIspHandle(sgks_mpi_manager_s *mpi);
int sgks_mpi_isp_MmapPhyAddr(sgks_isp_initParam_s * isp_config);
int sgks_mpi_isp_start(sgks_mpi_manager_s *mpi);
int sgks_mpi_isp_Init(sgks_isp_initParam_s *isp_config);

// nBrightness [0-255]
int sgks_mpi_isp_SetBrightness(int nBrightness);
int sgks_mpi_isp_GetBrightness(int *pBrightness);

// nSaturation [0-255]
int sgks_mpi_isp_SetSaturation(int nSaturation);
int sgks_mpi_isp_GetSaturation(int *pSaturation);
int sgks_mpi_isp_SetContrast(int enableAuto, int nContrast);
//int sgks_mpi_isp_SetHue(int nHue);
//int sgks_mpi_isp_GetHue(int *pHue);

//int sgks_mpi_isp_GetSystemGain(int *pGain);
int sgks_mpi_isp_GetExposureCurrentShutter(double *p_shutter);
//int sgks_mpi_isp_GetExposureCurrentGain(unsigned int *p_gain);
//int sgks_mpi_isp_GetExposureCurrentTarget(void);
//int sgks_mpi_isp_GetExposureCurrentLuma(void);
int sgks_mpi_isp_SetExposureRoi(int roi[96]);
//int sgks_mpi_isp_SetExposureMeterMode(unsigned int mode);
int sgks_mpi_isp_SetExposureType(sgks_mpi_isp_ExposureType_e type);
//int sgks_mpi_isp_SetAeSpeed(unsigned char ae_speed);
int sgks_mpi_isp_SetAeAttr(sgks_mpi_isp_AeAttr_s AeAttr);
int sgks_mpi_isp_GetAeAttr(sgks_mpi_isp_AeAttr_s *pAeAttr);
int sgks_mpi_isp_SetMeAttr(sgks_mpi_isp_MeAttr_s MeAttr);
int sgks_mpi_isp_GetMeAttr(sgks_mpi_isp_MeAttr_s *pMeAttr);

int sgks_mpi_isp_SetWhiteBalanceType(sgks_mpi_isp_WhiteBalanceType_e type);
//int sgks_mpi_isp_SetAwbSpeed(unsigned char awb_speed);
int sgks_mpi_isp_SetMwbAttr(sgks_mpi_isp_MwbAttr_s MwbAttr);
//int sgks_mpi_isp_GetMwbAttr(sgks_mpi_isp_MwbAttr_s *pMwbAttr);


signed int  gadi_isp_reset_3a_static(void* ispHandle);
signed int gadi_isp_set_wb_type(void* ispHandle, SGKS_ISP_WbTypeEnumT type);

int sgks_mpi_isp_Reset3A(sgks_mpi_manager_s *mpi);


#ifdef  __cplusplus
}
#endif

#endif






